<?php
class LoginController extends  Zend_Controller_Action{

	public function init(){}
	
	public function indexAction(){
	
		
		$request = $this->getRequest();

		if($request->isPost()){
			
			// getting the user submitted values
			$username = $request->getPost("username");
			$password 	= 	$request->getPost("password");

			
			// validate
			
			if($username == "" || $password == ""){
				$userMessage = Default_Service_Message::AUTH_INVALID_LOGIN;

				
			}else{
								
				if(Default_Service_Auth::doLogin($username, $password)){					
					if ( isset ( $_SESSION ['redirect_url'] ) && $_SESSION ['redirect_url'] != "" ) 
					{
	                                    // if yes...go to that
	                                    $url = $_SESSION ['redirect_url'];
	
	                                unset ( $_SESSION ['redirect_url'] ); // removing it from session
	
	
	                                    $this->_helper->redirector->gotoUrl (
	                                    Zend_Registry::get ( 'domain' ) . $url );
	                }
				    else
				    {
				    	
				    	if(Default_Service_Auth::isAdminLoggedIn()){
				    		$this->_helper->redirector("", "", "menu");	
				    	}
				    	else{
							$this->_helper->redirector("", "", "account");	
				    	}
					}

				}else{
					
					$userMessage = Default_Service_Message::AUTH_INVALID_LOGIN;
				
				}
				
				
				
			}
			
			if($userMessage != ""){
				$this->view->userMessage = $userMessage;				
			}
			
			
			
		}
		
		
		
	}


}